import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/home_business/section_all_page/section_all_logic.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/tools_base/appbar/base_app_bar.dart';
import 'package:tiktokadult/tools_base/loading/l_error_widget.dart';
import 'package:tiktokadult/tools_base/loading/loading_center_widget.dart';
import 'package:tiktokadult/tools_base/refresh/pull_refresh.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';

import '../../../hj_model/home/module_detail_model.dart';
import '../special_topic_detail/specail_topics_detail_page.dart';

class SectionAllPage extends StatelessWidget {
  final String id;

  const SectionAllPage(this.id, {super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: SectionAllLogic(id),
      builder: (logic) => Scaffold(
        appBar: BaseAppBar(title: "网黄女优"),
        body: () {
          if (logic.dataSource == null) {
            return LoadingCenterWidget();
          } else if (logic.dataSource!.isEmpty) {
            return CErrorWidget(
              retryOnTap: () => logic.onInitData(),
            );
          } else {
            return pullYsRefresh(
              onInit: (ctr) => logic.refreshController = ctr,
              onRefresh: (ctr) => logic.refreshData(),
              onLoading: (ctr) => logic.loadMoreData(),
              child: ListView.builder(
                padding: EdgeInsets.fromLTRB(16, 12, 16, 0),
                itemCount: logic.dataSource?.length ?? 0,
                itemBuilder: (context, index) {
                  AllSection model = logic.dataSource![index];
                  return InkWell(
                    onTap: () {
                      Get.to(SpecailTopicsDetailPage(model), preventDuplicates: false);
                    },
                    child: Container(
                      margin: EdgeInsets.only(bottom: 12),
                      padding: EdgeInsets.symmetric(horizontal: 12, vertical: 16),
                      decoration: BoxDecoration(
                        color: Color(0x1AFFFFFF),
                        borderRadius: BorderRadius.circular(4),
                      ),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            height: 60,
                            child: Row(
                              children: [
                                NetworkImageLoader(
                                  imageUrl: model.sectionCover,
                                  width: 60,
                                  height: 60,
                                  borderRadius: 50,
                                ),
                                12.sizeBoxW,
                                Expanded(
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      Text(
                                        model.sectionName ?? "",
                                        maxLines: 1,
                                        style: TextStyle(
                                          color: Color(0xE5FFFFFF),
                                          fontSize: 16,
                                          fontWeight: FontWeight.w500,
                                        ),
                                      ),
                                      8.sizeBoxH,
                                      Text(
                                        "作品 ${model.workCount}  粉丝 ${model.workCount}",
                                        maxLines: 1,
                                        style: TextStyle(
                                          color: Color(0xffFD2D55),
                                          fontSize: 12,
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ),
                          if (model.desc?.isNotEmpty == true)
                            Container(
                              padding: EdgeInsets.only(top: 12),
                              child: Text(
                                model.desc ?? "",
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Color(0xE5FFFFFF),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                        ],
                      ),
                    ),
                  );
                },
              ),
            );
          }
        }(),
      ),
    );
  }
}
